<?php
class ressourceext{
	protected $id,$ressourcetype,$name;

	function __construct($id,$ressourcetypeid,$name){
		$this->id = $id;
		$this->ressourcetype = ressourcetype::getRessourceTypeById($ressourcetypeid);
		$this->name = $name;

	}
	
	public function getId(){
		return $this->id;
	}

	public function getName(){
		return $this->name;	
	}
	
	public function getRessourceType(){
		return $this->ressourcetype;	
	}
	
	public static function generateOptionByRessourceTypeById($id,$default){
		$result = self::getRessourceExtByRessourceTypeById($id);
		$str="";
		while($row = $result->fetch_assoc()){
			$temp = new ressourceext($row['id'],$row['ressource_type_id'],$row['name']);
			$str = $str."<option name=\"".$temp->id."\" value=\"".$temp->id."\"";
			if($default == $temp->id){
				$str = $str." selected=selected ";
			}
			$str = $str.">".$temp->name."</option>";
			
			unset($temp);
		}
		return $str;
	}
	public static function getAllRessourceExt(){
		$conn = new dbmodifier();
		$query = "SELECT * FROM RESSOURCEEXT";
		$result = $conn->updateSQL($query);
		$conn->execute();
		return $result;
	}
	
	public static function getRessourceExtByRessourceTypeById($id){
		$conn = new dbmodifier();
		$query = "SELECT * FROM ressourceext WHERE ressource_type_id='".$id."'";
		$result = $conn->updateSQL($query);
		$conn->execute();
		return $result;	
	}
	public static function getRessourceExtByName($name){
		$conn = new dbmodifier();
		$name = $conn->db_connection->real_escape_string($name);
		$query = "SELECT * FROM ressourceext WHERE name='".$name."'";
		$result = $conn->updateSQL($query);
		$conn->execute();
		$row = $result->fetch_array(MYSQLI_ASSOC);
		$var = new ressourceext($row['id'],$row['ressource_type_id'],$row['name']);		
		return $var;	
	}

	public static function getRessourceExtById($id){
		$conn = new dbmodifier();
		$id = $conn->db_connection->real_escape_string($id);
		$query = "SELECT * FROM ressourceext WHERE id='".$id."'";
		$result = $conn->updateSQL($query);
		$conn->execute();
		$row = $result->fetch_array(MYSQLI_ASSOC);
		$var = new ressourceext($row['id'],$row['ressource_type_id'],$row['name']);	
		return $var;	

	}
}
?>
